#!/usr/bin/perl -w

#
# this program expects a .csh type path as the argument, and returns a
# cleaned up list on stdout as the result. it removes repeated
# directories in the path and removes any references to non-existant
# directories.
#
# $Copyright: (c) 1997-2009 Thomas Dejanovic $ 
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# process the path.

if (@ARGV) {
    $path = shift @ARGV;
} else {
    print "usage : fix_path <path value>\n\n";
    print "where <path vale> is a .csh type path (ie. dir[:dir[:dir]])\n\n";
}

# lets dissassemble the path.
my @path_l = split(':', $path);
my @l = ();

foreach my $d (@path_l) { 
    # check to see if we already have this directory.
    if (!grep(/^$d$/,@l)) {
	# check to see that it exists
	if (-e $d) {
	    push(@l, $d);
	    # print(STDERR "$d\n");
	}
    }
}

# now print out the path
print join(':',@l);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Local Variables:
# mode: perl
# End:



